package com.Service;

import com.Utils.RedisUtil;
import com.Utils.Sample;
import com.aliyun.tea.utils.StringUtils;
import com.common.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SmsService {
    private final static String SMS_CODE_KEY_PRE = "%s:%s";
    @Autowired
    private RedisUtil redisUtil;
    public Result send(String phoneNumber, String bizType) {
        String confirmCode = Sample.message(phoneNumber);
        if (!StringUtils.isEmpty(confirmCode)) {
            boolean set = redisUtil.set(String.format(SMS_CODE_KEY_PRE, bizType, phoneNumber), confirmCode, 300);
            return new Result().ok("success");
        } else {
            return new Result().error("发送失败");
        }
    }
}
